package cn.itcast.controller;

import cn.itcast.entity.Result;
import cn.itcast.service.LoginService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.Map;

@RestController
@RequestMapping("/sms")
public class LoginController {


    @Reference
    private LoginService loginService;
    /**
     * 发送验证码
     * 请求方式: Post
     * 请求路径: /sms/sendLoginCode?phone=
     * 请求参数: 手机号
     * 返回值: Result
     */
    @PostMapping("/sendLoginCode")
    public Result sendSmsToPhone(@PathParam("phone") String phone ){
        //String phone = (String) map.get("phone");
        Boolean result = loginService.sendSmsToPhone(phone);
        return new Result(result,"发送验证码成功",null);

    }

    /**
     * 预约异步请求发送验证码
     * 请求方式: post
     * 请求路径: /sms/sendCode
     * 请求参数: phone
     * 返回值: result
     */
    @PostMapping("/sendCode")
    public Result sendSms(@PathParam("phone") String phone ){
        Boolean result = loginService.sendSmsToPhone(phone);
        if (!result){
            return new Result(result,"发送验证码失败",null);
        }
        return new Result(result,"发送验证码成功",null);
    }
}
